package com.geekchique.runningbuddy.view.overlay;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.location.Location;

import com.geekchique.runningbuddy.R;
import com.geekchique.runningbuddy.activity.CurrentRunMap;
import com.google.android.maps.Overlay;
import com.google.googlenav.DrivingDirection;

public class DetailsOverlay extends Overlay {

	CurrentRunMap mapOfJogActivity = null;
	DrivingDirection drivingDirections = null;

	@SuppressWarnings("unused")
	private Bitmap PIN_START = null;
	private Bitmap INFO_LOWER_LEFT = null;
    protected List<Location> path = new ArrayList<Location>();
	int[] screenCoords = {0,0};
	boolean firstInPath;
	boolean first = true;
	private String time = "00:00:00.00";
	private Calendar calendar;
	private String dateString;

	public DetailsOverlay(CurrentRunMap map, Bitmap infoImageBG) {
		mapOfJogActivity = map;
		INFO_LOWER_LEFT = infoImageBG;

		calendar = new GregorianCalendar();
		this.dateString = new String (Integer.toString(calendar.get(Calendar.DAY_OF_MONTH)) + '/' + Integer.toString(calendar.get(Calendar.MONTH)) + '/' + Integer.toString(calendar.get(Calendar.YEAR)));
	}

	public void draw(Canvas canvas, PixelCalculator pixelCalc, boolean shadow) {
		super.draw(canvas, pixelCalc, shadow);
		if (!shadow)
		{
			drawDetailsIndicator(canvas);
		}
	}

	private void drawDetailsIndicator(Canvas canvas) {
		int totalHeightOfView = this.mapOfJogActivity.findViewById(R.id.map).getHeight();

		canvas.drawBitmap(
				this.INFO_LOWER_LEFT,
				0,
				totalHeightOfView - this.INFO_LOWER_LEFT.height(),
				getRoutePathPainter());

		canvas.drawText(this.time, 5, totalHeightOfView - 5, getJourneyTimePainter());
		canvas.drawText(this.dateString, 4, totalHeightOfView - 35, getJourneyDistPainter()); // 2, 271

	}

	protected Paint getJourneyTimePainter(){
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setARGB(255,255,255,255);
		paint.setStrokeWidth(1);
		paint.setStyle(Paint.Style.FILL_AND_STROKE);
		paint.setTextSize(24);
		return paint;
	}

	protected Paint getJourneyDistPainter(){
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setARGB(255,255,255,255);
		paint.setStrokeWidth(1);
		paint.setStyle(Paint.Style.FILL_AND_STROKE);
		paint.setTextSize(16);
		return paint;
	}

	protected Paint getRoutePathPainter(){
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setStrokeWidth(4);
		paint.setARGB(175, 113, 105, 252);
		paint.setStyle(Paint.Style.STROKE);
		return paint;
	}

	public void addLocationToPath(Location pointLocation) {
		path.add(pointLocation);
	}

	public void setTime(String time){
		this.time = time;
	}
}

